package com.chapter16.Runnable_;

/**
 * @author 宋鑫宇
 * @version 1.0
 */
public class Runnable02 {
    public static void main(String[] args) {
        C1 c1 = new C1();
        C2 c2 = new C2();
        Thread thread = new Thread(c1);
        thread.start();
        thread = new Thread(c2);
        thread.start();
    }
}

class C1 implements Runnable {
    int count = 0;

    @Override
    public void run() {
        while (true) {
            System.out.println("c1...." + (++count) + Thread.currentThread().getName());
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            if (count == 10) {
                break;
            }
        }
    }
}

class C2 implements Runnable {
    int count = 0;

    @Override
    public void run() {
        while (true) {
            System.out.println("C2..." + (++count) + Thread.currentThread().getName());
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            if (count == 10) {
                break;
            }
        }
    }
}
